package com.vertygoeclypse.multitimer;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.NumberPicker;
//--------------------------------------------------------------------------------------------------
public class AddDialog extends DialogFragment {
    Button  canlbtn, sbtbtn;
    EditText tagvalue;
    NumberPicker minnp, secnp;
    Dialog cusd;
    CheckBox ckb;
    boolean savechkbx=true;
    onSubmitListener minListener, secListener, tagListener, chkbxListener;

    interface onSubmitListener{
        void setOSMinListener(String arg);
        void setOSSecListener(String arg);
        void setOSTagListener(String arg);
        void setOSCkbListener(String arg);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog cusd = new Dialog(getActivity(),R.style.Theme_MultiTimer_Dialog);
    cusd.setContentView(R.layout.dialogbox);
    cusd.show();
    canlbtn = (Button) cusd.findViewById(R.id.cancelbtn);
    sbtbtn = (Button) cusd.findViewById(R.id.submitbtn);
    minnp = (NumberPicker) cusd.findViewById(R.id.numberPicker1);
    secnp = (NumberPicker) cusd.findViewById(R.id.numberPicker2);
    tagvalue = (EditText) cusd.findViewById(R.id.tagname);
    ckb = (CheckBox) cusd.findViewById(R.id.savecheckBox);
    canlbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cusd.dismiss();
        }
    });
    sbtbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MainActivity myActivity = (MainActivity) getActivity();
            myActivity.setOSMinListener(String.valueOf(minnp.getValue()));
            myActivity.setOSSecListener(String.valueOf(secnp.getValue()));
            myActivity.setOSTagListener(tagvalue.getText().toString());
            myActivity.setOSCkbListener(String.valueOf(savechkbx));
            myActivity.workOutResults();
            cusd.dismiss();
        }
    });
    minnp.setMaxValue(59);
    minnp.setMinValue(0);
    minnp.setWrapSelectorWheel(false);
    minnp.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker numberPicker, int oldVal, int newVal) { }
    });
    secnp.setMaxValue(59);
    secnp.setMinValue(0);
    secnp.setWrapSelectorWheel(false);
    secnp.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker numberPicker, int oldVal, int newVal) { }
    });
    ckb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if(isChecked){
                savechkbx = true;
            } else {
                savechkbx = false;
            }
        }
    });
        return cusd;
    }
}
